package com.fenda.mybleapplication.study.page;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;

import android.os.Bundle;

import com.fenda.mybleapplication.R;
import com.fenda.mybleapplication.databinding.ActivityMainBinding;
import com.fenda.mybleapplication.databinding.ActivityViewModelBinding;
import com.fenda.mybleapplication.study.ViewModelWithLiveData;
import com.fenda.mybleapplication.study.model.ViewModelLive;

public class ViewModelActivity extends AppCompatActivity {

    private ActivityViewModelBinding binding1;
    private ViewModelLive viewModelLive;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        viewModelLive = new ViewModelProvider(this,new ViewModelProvider.NewInstanceFactory()).get(ViewModelLive.class);
        viewModelLive = ViewModelProvider.AndroidViewModelFactory
                .getInstance(this.getApplication()).create(ViewModelLive.class);
        binding1 = DataBindingUtil.setContentView(ViewModelActivity.this, R.layout.activity_view_model);
        binding1.setData1(viewModelLive);
        binding1.setLifecycleOwner(this);
    }
}